import * as plugins from "@/plugins";
import { createPinia, type PiniaPlugin } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";

// 定义插件类型
type Plugins = { [key: string]: PiniaPlugin };

// 使用类型断言
const piniaPlugins = { ...plugins, piniaPluginPersistedstate } as Plugins;

const pinia = createPinia();
for (const key in piniaPlugins) {
  if (Object.prototype.hasOwnProperty.call(piniaPlugins, key)) {
    const plugin = piniaPlugins[key];
    pinia.use(plugin);
  }
}

export default pinia;
